/*
 *  SPI ROM header file
 *
 */

#include "mfutils.h"
#ifndef _SPI_SD_H_
#define _SPI_SD_H_


#define sd_CMDSIZE          	  6
#define sd_BLOCKSIZE			  512

#define GO_IDLE_STATE 0
#define A_GO_OP_CONDITION 41
#define A_COMMAND 55
#define READ_SINGLE_BLOCK 17
#define READ_MULTIPLE_BLOCK 18
#define STOP_TRANSMISSION 12

/* ------------------------------------------------------------------------ *
 *  SPI Controller                                                          *
 * ------------------------------------------------------------------------ */

#define SPI_SPICC1         *(volatile ioport Uint16*)(0x3000)
#define SPI_SPICC2         *(volatile ioport Uint16*)(0x3001)
#define SPI_SPIDC1         *(volatile ioport Uint16*)(0x3002)
#define SPI_SPIDC2         *(volatile ioport Uint16*)(0x3003)
#define SPI_SPICR1         *(volatile ioport Uint16*)(0x3004)
#define SPI_SPICR2         *(volatile ioport Uint16*)(0x3005)
#define SPI_SPISR1         *(volatile ioport Uint16*)(0x3006)
#define SPI_SPISR2         *(volatile ioport Uint16*)(0x3007)
#define SPI_SPIDR1         *(volatile ioport Uint16*)(0x3008)
#define SPI_SPIDR2         *(volatile ioport Uint16*)(0x3009)

/* ------------------------------------------------------------------------ *
 *  Prototype                                                               *
 * ------------------------------------------------------------------------ */

void sd_init();
char sd_cycle(Uint16 *buf, Uint16 len, char readonly);
char ReadByte();
char SD_R1_Response(char r1, Uint16 buf);
char SendCommand(Uint16 comm, unsigned long arg);
void sd_init_cycle();
char sd_read_cycle(volatile unsigned char *buf, Uint16 len, char readonly, Uint16 offset);
char WaitForStartToken(Uint16 time);


static Uint16 sdbuf[sd_CMDSIZE + 8];
char sd_read_single_block(unsigned long start_block);



#endif
